<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Repositories\QuizRepository;

class Quiz extends JsonResource
{

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $status = $this->status;

        return [
            'id' => $this->id,
            'name' => $this->name,
            'options' => $this->options,
            'status_name' => $this->status !== null ? __(array_get(QuizRepository::$status, $status)) : null,
            'status' => $status,
            'is_stopped' => string_to_datetime($this->stop_at) <= now(),
            'creater' => new User($this->creater),
            'group' => new Group($request->route('group') ?: $this->group),
			'links' => [
                'self' => route('quiz', ['id' => $this->id])
            ],
        ];
    }
}
